import * as type from './type'

import axios from 'axios'

const state={
    banners:null
}       

export const actionCreators = {
    get_banner(){
        return dispatch =>{
            console.log(2)
            axios({
                url:'/api/getIndexFirstPaintInfo',
                params:{
                    cid:'', 
                    zy_ids:'p8_c4_l4',
                    app_name:'zhe',
                    app_version:'',
                    platform:'',
                    catname:'newest_zhe'                
                }
            }).then(data=>{
                //创建动作
                let action = {
                    type:type.GET_BANNER,
                    payload:data.data.adsInfo.slide_ads.config.slide
                }
                //发送动作
                dispatch( action )

            })
              .catch(error=>console.log(error))
        }
    
    }
}

export const reducer = ( prevState = state , action ) => {
    //复制一层数据
    const  newState = {
        ...prevState
    }
    switch ( action.type ) {
        case type.GET_BANNER:
            console.log(1)
            newState.banners = action.payload
            break;
    
        default:
            break;
    }
    return newState
}